/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.openbookformat.tags;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author MUFEED
 */
public class PagebreakTag implements Tag{
    private int pageNumber;
    private boolean alphaNumbers;

    public PagebreakTag(int pageNumber) {
        this(pageNumber, false);
    }

    public PagebreakTag(int pageNumber, boolean alphaNumbers) {
        this.pageNumber = pageNumber;
        this.alphaNumbers = alphaNumbers;
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public boolean isAlphaNumbers() {
        return alphaNumbers;
    }

    public void setAlphaNumbers(boolean alphaNumbers) {
        this.alphaNumbers = alphaNumbers;
    }

    @Override
    public String toString() {
        return "<pagebreak n ='" + pageNumber + "' />";
    }
    
    public static final String TAG_PATTERN = 
        "<pagebreak\\sn\\s*='(\\d+)'\\s?/>";
    public static PagebreakTag parse(String text) throws TagParsingException {
        if(!text.matches(TAG_PATTERN))
            throw new TagParsingException("Parsing error in FnTextTag:" + text);
        
        Pattern pattern = Pattern.compile(TAG_PATTERN);
        Matcher matcher = pattern.matcher(text);
       
        matcher.find();        
        String mark = matcher.replaceAll("$1");
        return new PagebreakTag(Integer.parseInt(mark));
    }

    
}
